package com.lovo;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class practice_7_18 {

    FileInputStream fileInputStream = null;
    FileOutputStream fileOutputStream = null;

    //拷贝
    public void FileCopy(String Path, String newPath) {


        try {
            fileOutputStream = new FileOutputStream(newPath);
            fileInputStream = new FileInputStream(Path);
            int b = 0;
            while ((b = fileInputStream.read()) != -1) {
                fileOutputStream.write(b);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public void FileTextAdd(String str) {
        try {
            fileOutputStream = new FileOutputStream("d:/a.txt", true);
            fileOutputStream.write(str.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public static void main(String[] args) {
        practice_7_18 obj = new practice_7_18();
        //1
//        obj.FileCopy("d:/a.txt", "d:/b.txt");
        //2
        obj.FileTextAdd("000asdasd000");
    }
}



